import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 三方应用管理
 * @date: 2018-9-29


 */
import { getResponse, createPagination, parseParameters } from 'utils/utils';
import { queryMapIdpValue } from 'services/api';
import { fetchOpenAppList as _fetchOpenAppList, deleteOpenApp as _deleteOpenApp, updateOpenApp as _updateOpenApp, createOpenApp as _createOpenApp, enabledOpenApp as _enabledOpenApp, disabledOpenApp as _disabledOpenApp, fetchOpenAppDetail as _fetchOpenAppDetail } from "../services/openAppService";
export default {
  namespace: 'openApp',
  state: {
    openAppList: [],
    // 列表数据
    openAppDetail: {},
    // 详情数据
    pagination: {},
    // 分页对象
    channelTypes: [],
    // 渠道列表
    codeList: [] // 应用编码列表

  },
  effects: {
    // *init(_, { call, put }) {
    //   const res = yield call(queryUnifyIdpValue, 'CIAM.CHANNEL');
    //   const data = getResponse(res);
    //   if (data) {
    //     yield put({
    //       type: 'updateState',
    //       payload: {
    //         channelTypes: data,
    //       },
    //     });
    //   }
    // },
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_, _ref) {
      var put, call, list, channelTypes, codeList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              put = _ref.put, call = _ref.call;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryMapIdpValue, {
                channelTypes: 'CIAM.CHANNEL',
                codeList: 'CIAM.OPEN_APP_CODE'
              });

            case 4:
              _context.t1 = _context.sent;
              list = (0, _context.t0)(_context.t1);

              if (!list) {
                _context.next = 10;
                break;
              }

              channelTypes = list.channelTypes, codeList = list.codeList;
              _context.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  channelTypes: channelTypes,
                  codeList: codeList
                }
              });

            case 10:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 获取列表信息
    fetchOpenAppList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchOpenAppList(_ref2, _ref3) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchOpenAppList$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.next = 4;
              return call(_fetchOpenAppList, parseParameters(payload));

            case 4:
              res = _context2.sent;
              list = getResponse(res);

              if (!list) {
                _context2.next = 9;
                break;
              }

              _context2.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  openAppList: list.content,
                  pagination: createPagination(list)
                }
              });

            case 9:
              return _context2.abrupt("return", list);

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, fetchOpenAppList);
    }),
    // 查询详情
    fetchOpenAppDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchOpenAppDetail(_ref4, _ref5) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function fetchOpenAppDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call, put = _ref5.put;
              _context3.next = 4;
              return call(_fetchOpenAppDetail, payload);

            case 4:
              res = _context3.sent;
              list = getResponse(res);

              if (!list) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  openAppDetail: list
                }
              });

            case 9:
              return _context3.abrupt("return", list);

            case 10:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchOpenAppDetail);
    }),
    // 更新
    updateOpenApp: /*#__PURE__*/_regeneratorRuntime.mark(function updateOpenApp(_ref6, _ref7) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateOpenApp$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call;
              _context4.next = 4;
              return call(_updateOpenApp, payload);

            case 4:
              res = _context4.sent;
              return _context4.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, updateOpenApp);
    }),
    // 新建
    createOpenApp: /*#__PURE__*/_regeneratorRuntime.mark(function createOpenApp(_ref8, _ref9) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createOpenApp$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call;
              _context5.next = 4;
              return call(_createOpenApp, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, createOpenApp);
    }),
    // 启用
    enabledOpenApp: /*#__PURE__*/_regeneratorRuntime.mark(function enabledOpenApp(_ref10, _ref11) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function enabledOpenApp$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call;
              _context6.next = 4;
              return call(_enabledOpenApp, payload);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, enabledOpenApp);
    }),
    // 禁用
    disabledOpenApp: /*#__PURE__*/_regeneratorRuntime.mark(function disabledOpenApp(_ref12, _ref13) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function disabledOpenApp$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call;
              _context7.next = 4;
              return call(_disabledOpenApp, payload);

            case 4:
              res = _context7.sent;
              return _context7.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, disabledOpenApp);
    }),
    // 删除
    deleteOpenApp: /*#__PURE__*/_regeneratorRuntime.mark(function deleteOpenApp(_ref14, _ref15) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteOpenApp$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.next = 4;
              return call(_deleteOpenApp, payload);

            case 4:
              res = _context8.sent;
              return _context8.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context8.stop();
          }
        }
      }, deleteOpenApp);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref16) {
      var payload = _ref16.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};